<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - id:000977,sync:fuzzer2,src:001052.lcov_info_final - src/scanner.cpp</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - scanner.cpp<span style="font-size: 80%;"> (source / <a href="scanner.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">id:000977,sync:fuzzer2,src:001052.lcov_info_final</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">166</td>
            <td class="headerCovTableEntry">178</td>
            <td class="headerCovTableEntryHi">93.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2016-03-13 10:42:47</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">22</td>
            <td class="headerCovTableEntry">23</td>
            <td class="headerCovTableEntryHi">95.7 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;cassert&gt;</a>
<span class="lineNum">       2 </span>            : #include &lt;memory&gt;
<span class="lineNum">       3 </span>            : 
<span class="lineNum">       4 </span>            : #include &quot;exp.h&quot;
<span class="lineNum">       5 </span>            : #include &quot;scanner.h&quot;
<span class="lineNum">       6 </span>            : #include &quot;token.h&quot;
<span class="lineNum">       7 </span>            : #include &quot;yaml-cpp/exceptions.h&quot;  // IWYU pragma: keep
<a name="8"><span class="lineNum">       8 </span>            : </a>
<span class="lineNum">       9 </span>            : namespace YAML {
<span class="lineNum">      10 </span><span class="lineCov">       2036 : Scanner::Scanner(std::istream&amp; in)</span>
<span class="lineNum">      11 </span>            :     : INPUT(in),
<span class="lineNum">      12 </span>            :       m_startedStream(false),
<span class="lineNum">      13 </span>            :       m_endedStream(false),
<span class="lineNum">      14 </span>            :       m_simpleKeyAllowed(false),
<a name="15"><span class="lineNum">      15 </span><span class="lineCov">       2036 :       m_canBeJSONFlow(false) {}</span></a>
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span><span class="lineCov">       2036 : Scanner::~Scanner() {}</span>
<span class="lineNum">      18 </span>            : 
<a name="19"><span class="lineNum">      19 </span>            : // empty</a>
<span class="lineNum">      20 </span>            : // . Returns true if there are no more tokens to be read
<span class="lineNum">      21 </span><span class="lineCov">     396553 : bool Scanner::empty() {</span>
<span class="lineNum">      22 </span><span class="lineCov">     396553 :   EnsureTokensInQueue();</span>
<span class="lineNum">      23 </span><span class="lineCov">     395969 :   return m_tokens.empty();</span>
<span class="lineNum">      24 </span>            : }
<span class="lineNum">      25 </span>            : 
<a name="26"><span class="lineNum">      26 </span>            : // pop</a>
<span class="lineNum">      27 </span>            : // . Simply removes the next token on the queue.
<span class="lineNum">      28 </span><span class="lineCov">     201710 : void Scanner::pop() {</span>
<span class="lineNum">      29 </span><span class="lineCov">     201710 :   EnsureTokensInQueue();</span>
<span class="lineNum">      30 </span><span class="lineCov">     201710 :   if (!m_tokens.empty())</span>
<span class="lineNum">      31 </span><span class="lineCov">     201710 :     m_tokens.pop();</span>
<span class="lineNum">      32 </span><span class="lineCov">     201710 : }</span>
<span class="lineNum">      33 </span>            : 
<a name="34"><span class="lineNum">      34 </span>            : // peek</a>
<span class="lineNum">      35 </span>            : // . Returns (but does not remove) the next token on the queue.
<span class="lineNum">      36 </span><span class="lineCov">     774820 : Token&amp; Scanner::peek() {</span>
<span class="lineNum">      37 </span><span class="lineCov">     774820 :   EnsureTokensInQueue();</span>
<span class="lineNum">      38 </span><span class="lineCov">     774820 :   assert(!m_tokens.empty());  // should we be asserting here? I mean, we really</span>
<span class="lineNum">      39 </span>            :                               // just be checking
<span class="lineNum">      40 </span>            :                               // if it's empty before peeking.
<span class="lineNum">      41 </span>            : 
<span class="lineNum">      42 </span>            : #if 0
<span class="lineNum">      43 </span>            :                 static Token *pLast = 0;
<span class="lineNum">      44 </span>            :                 if(pLast != &amp;m_tokens.front())
<span class="lineNum">      45 </span>            :                         std::cerr &lt;&lt; &quot;peek: &quot; &lt;&lt; m_tokens.front() &lt;&lt; &quot;\n&quot;;
<span class="lineNum">      46 </span>            :                 pLast = &amp;m_tokens.front();
<span class="lineNum">      47 </span>            : #endif
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span><span class="lineCov">     774820 :   return m_tokens.front();</span>
<span class="lineNum">      50 </span>            : }
<span class="lineNum">      51 </span>            : 
<a name="52"><span class="lineNum">      52 </span>            : // mark</a>
<span class="lineNum">      53 </span>            : // . Returns the current mark in the stream
<span class="lineNum">      54 </span><span class="lineCov">         43 : Mark Scanner::mark() const { return INPUT.mark(); }</span>
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            : // EnsureTokensInQueue
<a name="57"><span class="lineNum">      57 </span>            : // . Scan until there's a valid token at the front of the queue,</a>
<span class="lineNum">      58 </span>            : //   or we're sure the queue is empty.
<span class="lineNum">      59 </span><span class="lineCov">    1602612 : void Scanner::EnsureTokensInQueue() {</span>
<span class="lineNum">      60 </span><span class="lineCov">     229529 :   while (1) {</span>
<span class="lineNum">      61 </span><span class="lineCov">    1602612 :     if (!m_tokens.empty()) {</span>
<span class="lineNum">      62 </span><span class="lineCov">    1530849 :       Token&amp; token = m_tokens.front();</span>
<span class="lineNum">      63 </span>            : 
<span class="lineNum">      64 </span>            :       // if this guy's valid, then we're done
<span class="lineNum">      65 </span><span class="lineCov">    1530849 :       if (token.status == Token::VALID)</span>
<span class="lineNum">      66 </span><span class="lineCov">    1184701 :         return;</span>
<span class="lineNum">      67 </span>            : 
<span class="lineNum">      68 </span>            :       // here's where we clean up the impossible tokens
<span class="lineNum">      69 </span><span class="lineCov">     346148 :       if (token.status == Token::INVALID) {</span>
<span class="lineNum">      70 </span><span class="lineCov">      20490 :         m_tokens.pop();</span>
<span class="lineNum">      71 </span><span class="lineCov">      20490 :         continue;</span>
<span class="lineNum">      72 </span>            :       }
<span class="lineNum">      73 </span>            : 
<span class="lineNum">      74 </span>            :       // note: what's left are the unverified tokens
<span class="lineNum">      75 </span>            :     }
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span>            :     // no token? maybe we've actually finished
<span class="lineNum">      78 </span><span class="lineCov">     397421 :     if (m_endedStream)</span>
<span class="lineNum">      79 </span><span class="lineCov">     187798 :       return;</span>
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            :     // no? then scan...
<span class="lineNum">      82 </span><span class="lineCov">     209623 :     ScanNextToken();</span>
<span class="lineNum">      83 </span>            :   }
<span class="lineNum">      84 </span>            : }
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            : // ScanNextToken
<a name="87"><span class="lineNum">      87 </span>            : // . The main scanning function; here we branch out and</a>
<span class="lineNum">      88 </span>            : //   scan whatever the next token should be.
<span class="lineNum">      89 </span><span class="lineCov">     209623 : void Scanner::ScanNextToken() {</span>
<span class="lineNum">      90 </span><span class="lineCov">     209623 :   if (m_endedStream)</span>
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :     return;</span>
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span><span class="lineCov">     209623 :   if (!m_startedStream)</span>
<span class="lineNum">      94 </span><span class="lineCov">       2036 :     return StartStream();</span>
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            :   // get rid of whitespace, etc. (in between tokens it should be irrelevent)
<span class="lineNum">      97 </span><span class="lineCov">     207587 :   ScanToNextToken();</span>
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            :   // maybe need to end some blocks
<span class="lineNum">     100 </span><span class="lineCov">     207587 :   PopIndentToHere();</span>
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span>            :   // *****
<span class="lineNum">     103 </span>            :   // And now branch based on the next few characters!
<span class="lineNum">     104 </span>            :   // *****
<span class="lineNum">     105 </span>            : 
<span class="lineNum">     106 </span>            :   // end of stream
<span class="lineNum">     107 </span><span class="lineCov">     207587 :   if (!INPUT)</span>
<span class="lineNum">     108 </span><span class="lineCov">       1218 :     return EndStream();</span>
<span class="lineNum">     109 </span>            : 
<span class="lineNum">     110 </span><span class="lineCov">     206369 :   if (INPUT.column() == 0 &amp;&amp; INPUT.peek() == Keys::Directive)</span>
<span class="lineNum">     111 </span><span class="lineCov">       3161 :     return ScanDirective();</span>
<span class="lineNum">     112 </span>            : 
<span class="lineNum">     113 </span>            :   // document token
<span class="lineNum">     114 </span><span class="lineCov">     203208 :   if (INPUT.column() == 0 &amp;&amp; Exp::DocStart().Matches(INPUT))</span>
<span class="lineNum">     115 </span><span class="lineCov">        649 :     return ScanDocStart();</span>
<span class="lineNum">     116 </span>            : 
<span class="lineNum">     117 </span><span class="lineCov">     202559 :   if (INPUT.column() == 0 &amp;&amp; Exp::DocEnd().Matches(INPUT))</span>
<span class="lineNum">     118 </span><span class="lineCov">        745 :     return ScanDocEnd();</span>
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span>            :   // flow start/end/entry
<span class="lineNum">     121 </span><span class="lineCov">     201814 :   if (INPUT.peek() == Keys::FlowSeqStart || INPUT.peek() == Keys::FlowMapStart)</span>
<span class="lineNum">     122 </span><span class="lineCov">      58587 :     return ScanFlowStart();</span>
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span><span class="lineCov">     143227 :   if (INPUT.peek() == Keys::FlowSeqEnd || INPUT.peek() == Keys::FlowMapEnd)</span>
<span class="lineNum">     125 </span><span class="lineCov">       8258 :     return ScanFlowEnd();</span>
<span class="lineNum">     126 </span>            : 
<span class="lineNum">     127 </span><span class="lineCov">     134969 :   if (INPUT.peek() == Keys::FlowEntry)</span>
<span class="lineNum">     128 </span><span class="lineCov">      33951 :     return ScanFlowEntry();</span>
<span class="lineNum">     129 </span>            : 
<span class="lineNum">     130 </span>            :   // block/map stuff
<span class="lineNum">     131 </span><span class="lineCov">     101018 :   if (Exp::BlockEntry().Matches(INPUT))</span>
<span class="lineNum">     132 </span><span class="lineCov">      22472 :     return ScanBlockEntry();</span>
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span><span class="lineCov">      78546 :   if ((InBlockContext() ? Exp::Key() : Exp::KeyInFlow()).Matches(INPUT))</span>
<span class="lineNum">     135 </span><span class="lineCov">      15002 :     return ScanKey();</span>
<span class="lineNum">     136 </span>            : 
<span class="lineNum">     137 </span><span class="lineCov">      63544 :   if (GetValueRegex().Matches(INPUT))</span>
<span class="lineNum">     138 </span><span class="lineCov">      16753 :     return ScanValue();</span>
<span class="lineNum">     139 </span>            : 
<span class="lineNum">     140 </span>            :   // alias/anchor
<span class="lineNum">     141 </span><span class="lineCov">      46791 :   if (INPUT.peek() == Keys::Alias || INPUT.peek() == Keys::Anchor)</span>
<span class="lineNum">     142 </span><span class="lineCov">       5642 :     return ScanAnchorOrAlias();</span>
<span class="lineNum">     143 </span>            : 
<span class="lineNum">     144 </span>            :   // tag
<span class="lineNum">     145 </span><span class="lineCov">      41149 :   if (INPUT.peek() == Keys::Tag)</span>
<span class="lineNum">     146 </span><span class="lineCov">       8059 :     return ScanTag();</span>
<span class="lineNum">     147 </span>            : 
<span class="lineNum">     148 </span>            :   // special scalars
<span class="lineNum">     149 </span><span class="lineCov">      50172 :   if (InBlockContext() &amp;&amp; (INPUT.peek() == Keys::LiteralScalar ||</span>
<span class="lineNum">     150 </span><span class="lineCov">      17082 :                            INPUT.peek() == Keys::FoldedScalar))</span>
<span class="lineNum">     151 </span><span class="lineCov">        503 :     return ScanBlockScalar();</span>
<span class="lineNum">     152 </span>            : 
<span class="lineNum">     153 </span><span class="lineCov">      32587 :   if (INPUT.peek() == '\'' || INPUT.peek() == '\&quot;')</span>
<span class="lineNum">     154 </span><span class="lineCov">       2507 :     return ScanQuotedScalar();</span>
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span>            :   // plain scalars
<span class="lineNum">     157 </span><span class="lineCov">      60160 :   if ((InBlockContext() ? Exp::PlainScalar() : Exp::PlainScalarInFlow())</span>
<span class="lineNum">     158 </span><span class="lineCov">      60160 :           .Matches(INPUT))</span>
<span class="lineNum">     159 </span><span class="lineCov">      30054 :     return ScanPlainScalar();</span>
<span class="lineNum">     160 </span>            : 
<span class="lineNum">     161 </span>            :   // don't know what it is!
<span class="lineNum">     162 </span><span class="lineCov">         26 :   throw ParserException(INPUT.mark(), ErrorMsg::UNKNOWN_TOKEN);</span>
<span class="lineNum">     163 </span>            : }
<span class="lineNum">     164 </span>            : 
<a name="165"><span class="lineNum">     165 </span>            : // ScanToNextToken</a>
<span class="lineNum">     166 </span>            : // . Eats input until we reach the next token-like thing.
<span class="lineNum">     167 </span><span class="lineCov">     306386 : void Scanner::ScanToNextToken() {</span>
<span class="lineNum">     168 </span><span class="lineCov">      23616 :   while (1) {</span>
<span class="lineNum">     169 </span>            :     // first eat whitespace
<span class="lineNum">     170 </span><span class="lineCov">     381569 :     while (INPUT &amp;&amp; IsWhitespaceToBeEaten(INPUT.peek())) {</span>
<span class="lineNum">     171 </span><span class="lineCov">      75183 :       if (InBlockContext() &amp;&amp; Exp::Tab().Matches(INPUT))</span>
<span class="lineNum">     172 </span><span class="lineCov">        490 :         m_simpleKeyAllowed = false;</span>
<span class="lineNum">     173 </span><span class="lineCov">      75183 :       INPUT.eat(1);</span>
<span class="lineNum">     174 </span>            :     }
<span class="lineNum">     175 </span>            : 
<span class="lineNum">     176 </span>            :     // then eat a comment
<span class="lineNum">     177 </span><span class="lineCov">     231203 :     if (Exp::Comment().Matches(INPUT)) {</span>
<span class="lineNum">     178 </span>            :       // eat until line break
<span class="lineNum">     179 </span><span class="lineCov">     108810 :       while (INPUT &amp;&amp; !Exp::Break().Matches(INPUT))</span>
<span class="lineNum">     180 </span><span class="lineCov">      53889 :         INPUT.eat(1);</span>
<span class="lineNum">     181 </span>            :     }
<span class="lineNum">     182 </span>            : 
<span class="lineNum">     183 </span>            :     // if it's NOT a line break, then we're done!
<span class="lineNum">     184 </span><span class="lineCov">     231203 :     if (!Exp::Break().Matches(INPUT))</span>
<span class="lineNum">     185 </span><span class="lineCov">     207587 :       break;</span>
<span class="lineNum">     186 </span>            : 
<span class="lineNum">     187 </span>            :     // otherwise, let's eat the line break and keep going
<span class="lineNum">     188 </span><span class="lineCov">      23616 :     int n = Exp::Break().Match(INPUT);</span>
<span class="lineNum">     189 </span><span class="lineCov">      23616 :     INPUT.eat(n);</span>
<span class="lineNum">     190 </span>            : 
<span class="lineNum">     191 </span>            :     // oh yeah, and let's get rid of that simple key
<span class="lineNum">     192 </span><span class="lineCov">      23616 :     InvalidateSimpleKey();</span>
<span class="lineNum">     193 </span>            : 
<span class="lineNum">     194 </span>            :     // new line - we may be able to accept a simple key now
<span class="lineNum">     195 </span><span class="lineCov">      23616 :     if (InBlockContext())</span>
<span class="lineNum">     196 </span><span class="lineCov">      19476 :       m_simpleKeyAllowed = true;</span>
<span class="lineNum">     197 </span>            :   }
<span class="lineNum">     198 </span><span class="lineCov">     207587 : }</span>
<span class="lineNum">     199 </span>            : 
<span class="lineNum">     200 </span>            : ///////////////////////////////////////////////////////////////////////
<span class="lineNum">     201 </span>            : // Misc. helpers
<span class="lineNum">     202 </span>            : 
<span class="lineNum">     203 </span>            : // IsWhitespaceToBeEaten
<span class="lineNum">     204 </span>            : // . We can eat whitespace if it's a space or tab
<span class="lineNum">     205 </span>            : // . Note: originally tabs in block context couldn't be eaten
<span class="lineNum">     206 </span>            : //         &quot;where a simple key could be allowed
<span class="lineNum">     207 </span>            : //         (i.e., not at the beginning of a line, or following '-', '?', or
<span class="lineNum">     208 </span>            : // ':')&quot;
<span class="lineNum">     209 </span>            : //   I think this is wrong, since tabs can be non-content whitespace; it's just
<a name="210"><span class="lineNum">     210 </span>            : //   that they can't contribute to indentation, so once you've seen a tab in a</a>
<span class="lineNum">     211 </span>            : //   line, you can't start a simple key
<span class="lineNum">     212 </span><span class="lineCov">     305181 : bool Scanner::IsWhitespaceToBeEaten(char ch) {</span>
<span class="lineNum">     213 </span><span class="lineCov">     305181 :   if (ch == ' ')</span>
<span class="lineNum">     214 </span><span class="lineCov">      74661 :     return true;</span>
<span class="lineNum">     215 </span>            : 
<span class="lineNum">     216 </span><span class="lineCov">     230520 :   if (ch == '\t')</span>
<span class="lineNum">     217 </span><span class="lineCov">        522 :     return true;</span>
<span class="lineNum">     218 </span>            : 
<span class="lineNum">     219 </span><span class="lineCov">     229998 :   return false;</span>
<span class="lineNum">     220 </span>            : }
<span class="lineNum">     221 </span>            : 
<a name="222"><span class="lineNum">     222 </span>            : // GetValueRegex</a>
<span class="lineNum">     223 </span>            : // . Get the appropriate regex to check if it's a value token
<span class="lineNum">     224 </span><span class="lineCov">      63544 : const RegEx&amp; Scanner::GetValueRegex() const {</span>
<span class="lineNum">     225 </span><span class="lineCov">      63544 :   if (InBlockContext())</span>
<span class="lineNum">     226 </span><span class="lineCov">      41916 :     return Exp::Value();</span>
<span class="lineNum">     227 </span>            : 
<span class="lineNum">     228 </span><span class="lineCov">      21628 :   return m_canBeJSONFlow ? Exp::ValueInJSONFlow() : Exp::ValueInFlow();</span>
<span class="lineNum">     229 </span>            : }
<span class="lineNum">     230 </span>            : 
<a name="231"><span class="lineNum">     231 </span>            : // StartStream</a>
<span class="lineNum">     232 </span>            : // . Set the initial conditions for starting a stream.
<span class="lineNum">     233 </span><span class="lineCov">       2036 : void Scanner::StartStream() {</span>
<span class="lineNum">     234 </span><span class="lineCov">       2036 :   m_startedStream = true;</span>
<span class="lineNum">     235 </span><span class="lineCov">       2036 :   m_simpleKeyAllowed = true;</span>
<span class="lineNum">     236 </span><span class="lineCov">       4072 :   std::unique_ptr&lt;IndentMarker&gt; pIndent(new IndentMarker(-1, IndentMarker::NONE));</span>
<span class="lineNum">     237 </span><span class="lineCov">       2036 :   m_indentRefs.push_back(std::move(pIndent));</span>
<span class="lineNum">     238 </span><span class="lineCov">       2036 :   m_indents.push(&amp;m_indentRefs.back());</span>
<span class="lineNum">     239 </span><span class="lineCov">       2036 : }</span>
<span class="lineNum">     240 </span>            : 
<a name="241"><span class="lineNum">     241 </span>            : // EndStream</a>
<span class="lineNum">     242 </span>            : // . Close out the stream, finish up, etc.
<span class="lineNum">     243 </span><span class="lineCov">       1218 : void Scanner::EndStream() {</span>
<span class="lineNum">     244 </span>            :   // force newline
<span class="lineNum">     245 </span><span class="lineCov">       1218 :   if (INPUT.column() &gt; 0)</span>
<span class="lineNum">     246 </span><span class="lineCov">        523 :     INPUT.ResetColumn();</span>
<span class="lineNum">     247 </span>            : 
<span class="lineNum">     248 </span><span class="lineCov">       1218 :   PopAllIndents();</span>
<span class="lineNum">     249 </span><span class="lineCov">       1218 :   PopAllSimpleKeys();</span>
<span class="lineNum">     250 </span>            : 
<span class="lineNum">     251 </span><span class="lineCov">       1218 :   m_simpleKeyAllowed = false;</span>
<span class="lineNum">     252 </span><span class="lineCov">       1218 :   m_endedStream = true;</span>
<a name="253"><span class="lineNum">     253 </span><span class="lineCov">       1218 : }</span></a>
<span class="lineNum">     254 </span>            : 
<span class="lineNum">     255 </span><span class="lineCov">      42156 : Token* Scanner::PushToken(Token::TYPE type) {</span>
<span class="lineNum">     256 </span><span class="lineCov">      42156 :   m_tokens.push(Token(type, INPUT.mark()));</span>
<span class="lineNum">     257 </span><span class="lineCov">      42156 :   return &amp;m_tokens.back();</span>
<a name="258"><span class="lineNum">     258 </span>            : }</a>
<span class="lineNum">     259 </span>            : 
<span class="lineNum">     260 </span><span class="lineCov">      42156 : Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) const {</span>
<span class="lineNum">     261 </span><span class="lineCov">      42156 :   switch (type) {</span>
<span class="lineNum">     262 </span>            :     case IndentMarker::SEQ:
<span class="lineNum">     263 </span><span class="lineCov">      12409 :       return Token::BLOCK_SEQ_START;</span>
<span class="lineNum">     264 </span>            :     case IndentMarker::MAP:
<span class="lineNum">     265 </span><span class="lineCov">      29747 :       return Token::BLOCK_MAP_START;</span>
<span class="lineNum">     266 </span>            :     case IndentMarker::NONE:
<span class="lineNum">     267 </span><span class="lineNoCov">          0 :       assert(false);</span>
<span class="lineNum">     268 </span>            :       break;
<span class="lineNum">     269 </span>            :   }
<span class="lineNum">     270 </span><span class="lineNoCov">          0 :   assert(false);</span>
<span class="lineNum">     271 </span>            :   throw std::runtime_error(&quot;yaml-cpp: internal error, invalid indent type&quot;);
<span class="lineNum">     272 </span>            : }
<span class="lineNum">     273 </span>            : 
<span class="lineNum">     274 </span>            : // PushIndentTo
<span class="lineNum">     275 </span>            : // . Pushes an indentation onto the stack, and enqueues the
<a name="276"><span class="lineNum">     276 </span>            : //   proper token (sequence start or mapping start).</a>
<span class="lineNum">     277 </span>            : // . Returns the indent marker it generates (if any).
<span class="lineNum">     278 </span><span class="lineCov">      60590 : Scanner::IndentMarker* Scanner::PushIndentTo(int column,</span>
<span class="lineNum">     279 </span>            :                                              IndentMarker::INDENT_TYPE type) {
<span class="lineNum">     280 </span>            :   // are we in flow?
<span class="lineNum">     281 </span><span class="lineCov">      60590 :   if (InFlowContext())</span>
<span class="lineNum">     282 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">     283 </span>            : 
<span class="lineNum">     284 </span><span class="lineCov">     121180 :   std::unique_ptr&lt;IndentMarker&gt; pIndent(new IndentMarker(column, type));</span>
<span class="lineNum">     285 </span><span class="lineCov">      60590 :   IndentMarker&amp; indent = *pIndent;</span>
<span class="lineNum">     286 </span><span class="lineCov">      60590 :   const IndentMarker&amp; lastIndent = *m_indents.top();</span>
<span class="lineNum">     287 </span>            : 
<span class="lineNum">     288 </span>            :   // is this actually an indentation?
<span class="lineNum">     289 </span><span class="lineCov">      60590 :   if (indent.column &lt; lastIndent.column)</span>
<span class="lineNum">     290 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">     291 </span><span class="lineCov">      79711 :   if (indent.column == lastIndent.column &amp;&amp;</span>
<span class="lineNum">     292 </span><span class="lineCov">      19121 :       !(indent.type == IndentMarker::SEQ &amp;&amp;</span>
<span class="lineNum">     293 </span><span class="lineCov">      10733 :         lastIndent.type == IndentMarker::MAP))</span>
<span class="lineNum">     294 </span><span class="lineCov">      18434 :     return 0;</span>
<span class="lineNum">     295 </span>            : 
<span class="lineNum">     296 </span>            :   // push a start token
<span class="lineNum">     297 </span><span class="lineCov">      42156 :   indent.pStartToken = PushToken(GetStartTokenFor(type));</span>
<span class="lineNum">     298 </span>            : 
<span class="lineNum">     299 </span>            :   // and then the indent
<span class="lineNum">     300 </span><span class="lineCov">      42156 :   m_indents.push(&amp;indent);</span>
<span class="lineNum">     301 </span><span class="lineCov">      42156 :   m_indentRefs.push_back(std::move(pIndent));</span>
<span class="lineNum">     302 </span><span class="lineCov">      42156 :   return &amp;m_indentRefs.back();</span>
<span class="lineNum">     303 </span>            : }
<span class="lineNum">     304 </span>            : 
<span class="lineNum">     305 </span>            : // PopIndentToHere
<span class="lineNum">     306 </span>            : // . Pops indentations off the stack until we reach the current indentation
<span class="lineNum">     307 </span>            : // level,
<a name="308"><span class="lineNum">     308 </span>            : //   and enqueues the proper token each time.</a>
<span class="lineNum">     309 </span>            : // . Then pops all invalid indentations off.
<span class="lineNum">     310 </span><span class="lineCov">     207587 : void Scanner::PopIndentToHere() {</span>
<span class="lineNum">     311 </span>            :   // are we in flow?
<span class="lineNum">     312 </span><span class="lineCov">     207587 :   if (InFlowContext())</span>
<span class="lineNum">     313 </span><span class="lineCov">     121964 :     return;</span>
<span class="lineNum">     314 </span>            : 
<span class="lineNum">     315 </span>            :   // now pop away
<span class="lineNum">     316 </span><span class="lineCov">      17908 :   while (!m_indents.empty()) {</span>
<span class="lineNum">     317 </span><span class="lineCov">     103531 :     const IndentMarker&amp; indent = *m_indents.top();</span>
<span class="lineNum">     318 </span><span class="lineCov">     103531 :     if (indent.column &lt; INPUT.column())</span>
<span class="lineNum">     319 </span><span class="lineCov">      63095 :       break;</span>
<span class="lineNum">     320 </span><span class="lineCov">      86534 :     if (indent.column == INPUT.column() &amp;&amp;</span>
<span class="lineNum">     321 </span><span class="lineCov">      23570 :         !(indent.type == IndentMarker::SEQ &amp;&amp;</span>
<span class="lineNum">     322 </span><span class="lineCov">      11088 :           !Exp::BlockEntry().Matches(INPUT)))</span>
<span class="lineNum">     323 </span><span class="lineCov">      22528 :       break;</span>
<span class="lineNum">     324 </span>            : 
<span class="lineNum">     325 </span><span class="lineCov">      17908 :     PopIndent();</span>
<span class="lineNum">     326 </span>            :   }
<span class="lineNum">     327 </span>            : 
<span class="lineNum">     328 </span><span class="lineCov">        531 :   while (!m_indents.empty() &amp;&amp; m_indents.top()-&gt;status == IndentMarker::INVALID)</span>
<span class="lineNum">     329 </span><span class="lineCov">        531 :     PopIndent();</span>
<span class="lineNum">     330 </span>            : }
<span class="lineNum">     331 </span>            : 
<span class="lineNum">     332 </span>            : // PopAllIndents
<a name="333"><span class="lineNum">     333 </span>            : // . Pops all indentations (except for the base empty one) off the stack,</a>
<span class="lineNum">     334 </span>            : //   and enqueues the proper token each time.
<span class="lineNum">     335 </span><span class="lineCov">       5773 : void Scanner::PopAllIndents() {</span>
<span class="lineNum">     336 </span>            :   // are we in flow?
<span class="lineNum">     337 </span><span class="lineCov">       5773 :   if (InFlowContext())</span>
<span class="lineNum">     338 </span><span class="lineCov">        914 :     return;</span>
<span class="lineNum">     339 </span>            : 
<span class="lineNum">     340 </span>            :   // now pop away
<span class="lineNum">     341 </span><span class="lineCov">      14730 :   while (!m_indents.empty()) {</span>
<span class="lineNum">     342 </span><span class="lineCov">      19589 :     const IndentMarker&amp; indent = *m_indents.top();</span>
<span class="lineNum">     343 </span><span class="lineCov">      19589 :     if (indent.type == IndentMarker::NONE)</span>
<span class="lineNum">     344 </span><span class="lineCov">       4859 :       break;</span>
<span class="lineNum">     345 </span>            : 
<span class="lineNum">     346 </span><span class="lineCov">      14730 :     PopIndent();</span>
<span class="lineNum">     347 </span>            :   }
<span class="lineNum">     348 </span>            : }
<span class="lineNum">     349 </span>            : 
<a name="350"><span class="lineNum">     350 </span>            : // PopIndent</a>
<span class="lineNum">     351 </span>            : // . Pops a single indent, pushing the proper token
<span class="lineNum">     352 </span><span class="lineCov">      33169 : void Scanner::PopIndent() {</span>
<span class="lineNum">     353 </span><span class="lineCov">      33169 :   const IndentMarker&amp; indent = *m_indents.top();</span>
<span class="lineNum">     354 </span><span class="lineCov">      33169 :   m_indents.pop();</span>
<span class="lineNum">     355 </span>            : 
<span class="lineNum">     356 </span><span class="lineCov">      33169 :   if (indent.status != IndentMarker::VALID) {</span>
<span class="lineNum">     357 </span><span class="lineCov">       8914 :     InvalidateSimpleKey();</span>
<span class="lineNum">     358 </span><span class="lineCov">       8914 :     return;</span>
<span class="lineNum">     359 </span>            :   }
<span class="lineNum">     360 </span>            : 
<span class="lineNum">     361 </span><span class="lineCov">      24255 :   if (indent.type == IndentMarker::SEQ)</span>
<span class="lineNum">     362 </span><span class="lineCov">       9580 :     m_tokens.push(Token(Token::BLOCK_SEQ_END, INPUT.mark()));</span>
<span class="lineNum">     363 </span><span class="lineCov">      14675 :   else if (indent.type == IndentMarker::MAP)</span>
<span class="lineNum">     364 </span><span class="lineCov">      14675 :     m_tokens.push(Token(Token::BLOCK_MAP_END, INPUT.mark()));</span>
<span class="lineNum">     365 </span>            : }
<a name="366"><span class="lineNum">     366 </span>            : </a>
<span class="lineNum">     367 </span>            : // GetTopIndent
<span class="lineNum">     368 </span><span class="lineCov">      16986 : int Scanner::GetTopIndent() const {</span>
<span class="lineNum">     369 </span><span class="lineCov">      16986 :   if (m_indents.empty())</span>
<span class="lineNum">     370 </span><span class="lineNoCov">          0 :     return 0;</span>
<span class="lineNum">     371 </span><span class="lineCov">      16986 :   return m_indents.top()-&gt;column;</span>
<span class="lineNum">     372 </span>            : }
<span class="lineNum">     373 </span>            : 
<span class="lineNum">     374 </span>            : // ThrowParserException
<span class="lineNum">     375 </span>            : // . Throws a ParserException with the current token location
<a name="376"><span class="lineNum">     376 </span>            : //   (if available).</a>
<span class="lineNum">     377 </span>            : // . Does not parse any more tokens.
<span class="lineNum">     378 </span><span class="lineNoCov">          0 : void Scanner::ThrowParserException(const std::string&amp; msg) const {</span>
<span class="lineNum">     379 </span><span class="lineNoCov">          0 :   Mark mark = Mark::null_mark();</span>
<span class="lineNum">     380 </span><span class="lineNoCov">          0 :   if (!m_tokens.empty()) {</span>
<span class="lineNum">     381 </span><span class="lineNoCov">          0 :     const Token&amp; token = m_tokens.front();</span>
<span class="lineNum">     382 </span><span class="lineNoCov">          0 :     mark = token.mark;</span>
<span class="lineNum">     383 </span>            :   }
<a name="384"><span class="lineNum">     384 </span><span class="lineNoCov">          0 :   throw ParserException(mark, msg);</span></a>
<span class="lineNum">     385 </span>            : }
<span class="lineNum">     386 </span><span class="lineCov">       6108 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
